package com.bkgy.controller.qualityDaily.controller;

import com.bkgy.controller.qualityDaily.entity.pdo.QualityReq;
import com.bkgy.controller.qualityDaily.service.IQualitydailyPlankRepService;
import com.bkgy.sys.common.entity.ResultData;
import com.bkgy.util.DateUtil;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.util.Calendar;
import java.util.Date;

@Tag(name = "质量日报-汽车板生产情况")
@Controller
@RequestMapping("/qualityDailyPlank")
public class QualitydailyPlankRepController {

    @Autowired
    private IQualitydailyPlankRepService service;

    @ResponseBody
    @Operation(summary = "质量日报》三冷区域》汽车板生产情况折线图")
    @PostMapping("/plankLineRep")
    public ResultData plankLineRep() {
        return service.plankLineRep();
    }

    @ResponseBody
    @Operation(summary = "质量日报》三冷区域》汽车板生产情况")
    @PostMapping("/plankRep")
    public ResultData plankRep(@RequestBody QualityReq obj) {
        return service.plankRep(obj);
    }

    @Operation(summary = "【构建质量日报》汽车外板表历史数据】")
    @GetMapping("/buildQualitydailyRep")
    public ResultData<String> buildQualitydailyRep(String startDate, String endDate) {
        Date d1 = DateUtil.getStringToDate("yyyy-MM-dd", startDate);
        Date d2 = DateUtil.getStringToDate("yyyy-MM-dd", endDate);
        Calendar cal = Calendar.getInstance();
        cal.setTime(d1);
        while (d1.before(d2)) {
            service.buildPlankRepJob(d1);
            cal.add(Calendar.DAY_OF_MONTH, 1);
            d1 = cal.getTime();
        }
        return ResultData.ResultDataSuccess("SUCCESS");
    }
}
